//
//  ViewController.swift
//  RBVerifyInputViewDemo
//
//  Created by 冉彬 on 2024/1/10.
//

import UIKit

let screenWidth = UIScreen.main.bounds.size.width

class ViewController: UIViewController {

    /// 验证码输入框
    lazy var pwdView: RBVerifyInputView = {
        let count:Int = 6
        let space:CGFloat = (screenWidth - 52 - CGFloat(count*46))/CGFloat(count - 1)
        let v = RBVerifyInputView(frame: CGRect(x: 26, y: 80, width: screenWidth - 52, height: 46))
        v.count = count
        v.style = .splitblock(
            borderWidth: 1,
            borderRadius: 8,
            borderColor: .green,
            borderHighlightedColor: .blue,
            itemBackgroundColor: .yellow,
            itemBackgroundHighlightedColor: .red,
            itemSpacing: space)
        v.textFont = .systemFont(ofSize: 18, weight: .medium)
        v.isSecureTextEntry = true
        v.cursorColor = .purple
        v.cursorHeight = 16
        v.setCompleteHandler {[weak self] (result) in
            guard let self = self else {return}
            print("验证码 - \(result)")
            
        }
        return v
    }()
    
    /// 验证码输入框
    lazy var pwdView1: RBVerifyInputView = {
        let count:Int = 6
        let space:CGFloat = 0
        let v = RBVerifyInputView(frame: CGRect(x: 26, y: 146, width: screenWidth - 52, height: 46))
        v.count = count
        v.style = .splitblock(
            borderWidth: 1,
            borderRadius: 10,
            borderColor: .black,
            borderHighlightedColor: .black,
            itemBackgroundColor: .white,
            itemBackgroundHighlightedColor: .white,
            itemSpacing: space, isContinuous: true)
        v.textFont = .systemFont(ofSize: 18, weight: .medium)
        v.isSecureTextEntry = false
        v.cursorColor = .blue
        v.cursorHeight = 18
        v.setCompleteHandler {[weak self] (result) in
            guard let self = self else {return}
            print("验证码2 - \(result)")
            
        }
        return v
    }()
    
    /// 验证码输入框
    lazy var pwdView2: RBVerifyInputView = {
        let count:Int = 6
        let space:CGFloat = (screenWidth - 52 - CGFloat(count*46))/CGFloat(count - 1)
        let v = RBVerifyInputView(frame: CGRect(x: 26, y: 202, width: screenWidth - 52, height: 46))
        v.count = count
        v.style = .splitline(
            lineHeight: 3,
            lineRadius: 0.5,
            lineColor: .black,
            itemSpacing: space)
        v.textFont = .systemFont(ofSize: 18, weight: .medium)
        v.isSecureTextEntry = false
        v.cursorColor = .blue
        v.cursorHeight = 18
        v.setCompleteHandler {[weak self] (result) in
            guard let self = self else {return}
            print("验证码1 - \(result)")
            
        }
        return v
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        view.addSubview(pwdView)
        view.addSubview(pwdView1)
        view.addSubview(pwdView2)
        pwdView.startEditor()
    }


}

